<?php

namespace App\Http\Requests;

use Illuminate\Foundation\Http\FormRequest;

class AdminEditRequest extends FormRequest
{
    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        $return = [
            'phone' => 'required|numeric|regex:/^1[3456789][0-9]{9}$/|unique:admin,phone,' . $this->get('id') . ',id',
            'name' => 'required|unique:admin,name,' . $this->get('id') . ',id',
            //'email' => 'required|email|unique:admin,email,' . $this->get('id') . ',id',
            'role' => 'required'
        ];
        if ($this->get('password') || $this->get('password_confirmation')) {
            $return['password'] = 'required|confirmed|min:6|max:14';
        }
        return $return;
    }
}